<?php
session_start();
if ($_SESSION['auth'] != true && $_SESSION['rule'] != "PUBLISHER") {
	die('Not log in');
}
include ("edit_item.php");
include("includes/publisher_lib.php");
?>
<div class="input">
	<div class="title">Add item to channel</div>
	<div>
	<select id="addToCh" name="addToCh" style="width:200px">
	  <?php
	  $avch = getAvailableChannel($_SESSION['userdata']['username']);
	  
	  foreach($avch as $c)
	  {
		if($c['id']==$item['channelid'])
			echo "<option value=\"".$c['id']."\" selected>".$c['title']."</option>";
		else
			echo "<option value=\"".$c['id']."\">".$c['title']."</option>";
	  }
	  ?>
	 </select>
	</div>
</div>

<input type="button" value="Approve" id="approveItem" />
<input type="button" value="UnApprove" id="unApproveItem"/>
<script language="javascript" type="text/javascript">
$(document).ready (
	function () {
		var iid = '<? echo $iid; ?>';
		$('#approveItem').click(approveItem);
		$('#unApproveItem').click(unApproveItem);
	}
);
function approveItem(){
   $('#approveItem').attr("disabled", "true");
   $('#unApproveItem').attr("disabled", "true");
	var err = itemReq();
	if(err != ''){
		$('#status').show('fast');
		$('#status').html(err);
		return;
	}
	if(!confirm("Are you sure you want to APPROVE this item?")){
		return;
	}
	$('#status').show(200);
	$('#status').text('Waiting server');
	var serialize = $('form').serialize()+'&addToCh='+$('#addToCh').val();
	serialize = serialize.replace(/description/, "nothing");
	serialize += "&description="+escape(tinyMCE.getContent());
	$.post("publisher_operation.php?action=approve_item",serialize, 
	  function(data){
		$('#status').text(data);
		top.location='publisher.php';
	  });
}
function unApproveItem(){
   $('#approveItem').attr("disabled", "true");
   $('#unApproveItem').attr("disabled", "true");
	if(!confirm("Are you sure you want to UNAPPROVE this item?")){
		return;
	}
	$('#status').show(200);
	$('#status').text('Waiting server');
	var serialize = $('form').serialize();
	serialize = serialize.replace(/description/, "nothing");
	serialize += "&description="+escape(tinyMCE.getContent());
	$.post("publisher_operation.php?action=unapprove_item",serialize, 
	  function(data){
		$('#status').text(data);
		top.location='publisher.php';
	  });
}
</script>
